
package fileby.model.impl.sources.impl;

import com.google.inject.Inject;
import fileby.core.SourceType;
import fileby.model.impl.filemanagement.IFileHandler;
import fileby.model.impl.sources.IFileSource;
import fileby.model.impl.sources.IFileSourceManager;
import fileby.model.impl.sources.IFileSourceProvider;
import fileby.util.properties.IPropertyBundleProvider;
import java.io.File;

/**
 *
 * @author Ludwig Kjellstrom
 */
public class FileSourceFactory implements IFileSourceProvider{

    private IPropertyBundleProvider propertyBundleProvider;
    private IFileSource magicFileSource;
    private IFileHandler fileHandler;
    private IFileSourceManager fileSourceManager;

    @Inject
    public FileSourceFactory(IPropertyBundleProvider propertyBundleProvider,
            MagicBoxManager magicFileSource, IFileHandler fileHandler,
            IFileSourceManager fileSourceManager){
        this.propertyBundleProvider = propertyBundleProvider;
        this.magicFileSource = magicFileSource;
        this.fileHandler = fileHandler;
        this.fileSourceManager = fileSourceManager;
    }

    public IFileSource create(SourceType type) {
        return create(type, null);
    }

    public IFileSource create(SourceType type, String parameter) {
        switch (type) {
            case COMPUTER:
                return new ComputerSource(propertyBundleProvider);
            case FAVORITE:
                return FavoriteSource.getInstance();
            case MAGIC_BOX:
                return magicFileSource;
            case FOLDER:
                if (parameter != null) {
                    return new FolderSource(new File(parameter), this, fileHandler);
                }
            case SEARCH:
                if (parameter != null) {
                    return new SearchSource(parameter, propertyBundleProvider,
                            fileSourceManager.getCurrentSource().getFileItems());
                }
            default:
                System.err.println("Error creating source. Source: \"" + type.toString() +
                        "\". Param: \"" + parameter + "\"");
                return null;
        }
    }

}
